$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeNode" );

SmitearWebGL.Objects.Parser.Collada.DaeVisualScene = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node, yUp )
	{
		this.nodes = null;
		this._yUp = yUp == undefined ? 1 : yUp;

		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeVisualScene" );
	}
	,
	getEndTime : function()
	{
		return this.extras["end_time"];
	}
	,
	getFrameRate : function()
	{
		return this.extras[SmitearWebGL.Objects.Parser.Collada.Const.DAEMAX_FRAMERATE_PARAMETER];
	}
	,
	getStartTime : function()
	{
		return this.extras["start_time"];
	}
	,
	read : function( node )
	{
		$THROW( node.localName == SmitearWebGL.Objects.Parser.Collada.Const.DAE_VSCENE_ELEMENT,
		"expected a '" + SmitearWebGL.Objects.Parser.Collada.Const.DAE_VSCENE_ELEMENT + "' element" );

		this.nodes = [];

		this._super( node );

		$LOG( "reading visual scene: " + this.id );

		var nodeList = this.getNodeList(node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_NODE_ELEMENT);
		$THROW( nodeList.length, "require at least 1 <node> element!" );

		for( var i = 0; i < nodeList.length; i++ )
			this.nodes.push( new SmitearWebGL.Objects.Parser.Collada.DaeNode(this.document, nodeList[i], this._yUp) );

		var extraList = this.getNodeList( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_EXTRA_ELEMENT );
		for ( var i = 0; i < extraList.length; ++ i )
		{
			var extraNode = extraList[i];
			
			var programList = this.getNodeList( extraNode, SmitearWebGL.Objects.Parser.Collada.Const.DAE_TECHNIQUE_ELEMENT );

			for ( var j = 0; j < programList.length; ++ j )
			{
				var program = programList[j];
				
				var profile = this.getAttribute( program, SmitearWebGL.Objects.Parser.Collada.Const.DAE_PROFILE_ATTRIBUTE );

				switch( profile )
				{
					case SmitearWebGL.Objects.Parser.Collada.Const.DAEMAX_MAX_PROFILE:
						var frameRate = this.getNode(program, SmitearWebGL.Objects.Parser.Collada.Const.DAEMAX_FRAMERATE_PARAMETER);
						if( frameRate )
							this.extras[SmitearWebGL.Objects.Parser.Collada.Const.DAEMAX_FRAMERATE_PARAMETER] = parseFloat( this.getNodeContent( frameRate ) );
						break;

					case "FCOLLADA":
						var startTime = this.getNode(program, "start_time");
						if( startTime )
							this.extras["start_time"] = parseFloat( this.getNodeContent( startTime ) );
						var endTime = this.getNode(program, "end_time");
						if( endTime )
							this.extras["end_time"] = parseFloat( this.getNodeContent( endTime ) );
						break;

					default:
						break;
				}
			}
		}
	}
}
);